<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
    <meta name="keywords" content="逗逼联盟,逗逼阅读,无广告,小说" th:content="${systemInfo.metaKeywords}" />
    <meta name="description" content="做最简洁，最干净的小说聚合网站" th:content="${systemInfo.metaDescription}" />
    <title th:text="${systemInfo.sitename}+'-登录'">逗逼阅读-登录</title>
    <style>
        .content {
            padding-top: 10%;
        }

        .title-logo {
            height: 60px;
        }

        .title-item {
            font-size: 20px;
            font-weight: bolder;
            line-height: 30px;
            margin-top: 30px;
            text-align: center;
        }
    </style>
    <link rel="stylesheet" th:href="@{/css/home.css}" href="../../../static/css/home.css">
    <link rel="stylesheet" th:href="@{/css/custom_theme.css}" href="../../static/css/custom_theme.css">
    <link rel="stylesheet" th:href="@{/lib/layui/css/layui.css}" href="../../static/lib/layui/css/layui.css">
    <script th:replace="public/top::StatisticsJs"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js"></script>
</head>
<body class="theme-0">
<script th:src="@{/js/home.js}" src="../../static/js/home.js"></script>

<div class="layui-container">


    <div class="layui-row">
        <div class="title-item">
            <img src="../../static/imgs/icon/logo.png" th:src="@{/imgs/icon/logo.png}" class="title-logo">
            <span th:text="${systemInfo.sitename}">逗逼联盟-逗逼阅读</span><span style="font-size: 20px;font-weight: normal;line-height: 50px;"> |账号登录</span>
        </div>
    </div>

    <hr style="margin-top: 80px">

    <div class="layui-row">

        <form class="layui-form" action="/register/doRegister" method="post" lay-filter="register"
              style="margin-top: 20px">

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">
                        邮箱：
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" name="username" lay-verify="required|email" lay-reqtext="账号不能为空" placeholder="请输入账号或邮箱"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">
                       密码：
                    </label>
                    <div class="layui-input-inline">
                        <input type="password" name="password" lay-verify="required|password" lay-reqtext="密码不能为空"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">
                        验证码：
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" name="captcha" lay-verify="required" lay-reqtext="请输入验证码"
                               autocomplete="off" class="layui-input">
                    </div>
                    <img id="captchaPic" onclick="changeImg()" src="/">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">
                    </label>
                    <div class="layui-input-inline">
                        <input type="checkbox" name="rememberMe" checked value="true" lay-skin="primary" title="记住我">
                    </div>
                </div>
            </div>

            <div class="layui-form-item" style="margin-top: 50px">
                <button class="layui-btn layui-btn-danger layui-btn-fluid" lay-submit lay-filter="login">登  录</button>
            </div>

        </form>
    </div>

</div>
<script th:src="@{/lib/layui/layui.all.js}" src="../../static/lib/layui/layui.all.js"></script>
<script>

    function changeImg() {
        var img=document.getElementById("captchaPic");
        // 浏览器有一个缓存特性,
        // 第一次从服务器获取图片，浏览器第二次发送请求时发现地址没有改变，就会使用第一次的图片，而不会真正发送请求
        // 为了让浏览器每次都把请求发送给服务器，给一个时间参数
        img.src = "/verificationCode?t="+new Date().getTime(); // 给src赋一个新值，就会向新值的地址发送一次请求
    }
    changeImg();
</script>

<script type="text/javascript">
    layui.use(['form'], function () {
        var form = layui.form;
        // 进行登录操作
        form.on('submit(login)', function (data) {
            var index = parent.layer.load();
            $.ajax({
                url: '/doLogin',
                method: 'post',
                data: data.field,
                dataType: 'json',
                success: function (result) {
                    parent.layer.close(index);
                    var message = result.message;
                    if (result.success) {
                        parent.layer.msg('登录成功',{icon:1}, function () {
                            parent.window.location.reload();
                        });
                        return;
                    }
                    if (message == null || message == '' || message == undefined) {
                        message = '登录失败：未知错误';
                    }
                    parent.layer.msg(message, {icon: 5, anim: 6},function () {
                        changeImg();
                    });
                },
                error: function () {
                    changeImg();
                    parent.layer.close(index);
                    parent.layer.msg('登录失败：网络异常，请稍后再试', {icon: 5, anim: 6},function () {
                        changeImg();
                    });
                }
            });
            return false;
        });
    });
</script>
</body>
</html>